home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 17 / AMIGAplus Sonderheft 17 (1999)(ICP)(DE)[!].iso / Rexx / InvoiceText.rexx < prev    next >
OS/2 REXX Batch file  |  1998-01-13  |  5KB  |  222 lines

  1. /*
  2.         InvoiceText.rexx
  3.         $VER: 13 Jan 1998
  4. */
  5.  
  6. arg iNameCode
  7.  
  8. options results
  9.  
  10. /* Initialize */
  11. Quote = '22'x
  12. cInvoice = 0
  13.  
  14. DataPath = "S:TimeKeep/"
  15.  
  16. if iNameCode = "" then do
  17.     Say ""
  18.     Say "ERROR: No Client Code"
  19.     Say ""
  20.     exit
  21. end
  22.  
  23. /* Read Time Data */
  24. if ~ open('Time', DataPath||iNameCode||".time", 'R') then do
  25.     Say ""
  26.     Say "ERROR: .time NOT FOUND"
  27.     Say ""
  28.     exit
  29. end
  30.  
  31. t = readln('Time')
  32. parse var t '"'Client.NameCode'","'Client.Name'"'
  33.  
  34. /* Collate */
  35. Projects = "|"; nProjects = 0 ; Expenses = 0; Work = 0
  36. do while ~eof('Time')
  37.     t = readln('Time')
  38.     parse var t '"'tType'","'tProject'",'tInfo
  39.  
  40.     if tInfo == "" then leave
  41.  
  42.     if index(Projects, "|"tProject"|") = 0 then do
  43.         /* Project not found */
  44.         Projects = Projects||tProject"|"
  45.         nProjects = nProjects + 1
  46.         Projects.nProjects.Name = tProject
  47.  
  48.         if tType = "T" then do
  49.             Projects.nProjects.count = 1
  50.             Expenses.nProjects.count = 0
  51.             end
  52.         else do
  53.             Projects.nProjects.count = 0
  54.             Expenses.nProjects.count = 1
  55.         end
  56.  
  57.         cProject = nProjects; n = 1
  58.         end
  59.     else do
  60.         /* Project exists */
  61.         do lp = 1 to nProjects
  62.             if Projects.lp.Name = tProject then leave
  63.         end
  64.         cProject = lp
  65.  
  66.         if tType = "T" then do
  67.             Projects.lp.count = Projects.lp.count + 1
  68.             n = Projects.lp.count
  69.             end
  70.         else do
  71.             Expenses.lp.count = Expenses.lp.count + 1
  72.             n = Expenses.lp.count
  73.         end
  74.     end
  75.  
  76.     if tType = "T" then do
  77.         Projects.cProject.n.Info = tInfo
  78.         Work = 1
  79.         end
  80.     else do
  81.         Expenses.cProject.n.Info = tInfo
  82.         Expenses = 1
  83.     end
  84. end
  85.  
  86. call close('Time')
  87.  
  88. if nProjects = 0 then do
  89.     Say ""
  90.     Say "ERROR: NO Logged Time or Expenses"
  91.     Say ""
  92.     exit
  93. end
  94.  
  95. /* Read Invoice Number */
  96. if open('Invoice', DataPath||Client.NameCode||".invoice", 'R') then do
  97.     cInvoice = readln('Invoice')
  98.     call close('Invoice')
  99. end
  100.  
  101. cInvoice = cInvoice + 1
  102.  
  103. Client.Invoice = right(cInvoice, 2, "0")
  104.  
  105. /* Create Invoice */
  106. call open('Out', DataPath"/TimeKeep/Invoice."Client.NameCode''Client.Invoice, 'W')
  107.  
  108. /* Invoice # */
  109. call writeln('Out', "Invoice #"Client.NameCode''Client.Invoice)
  110.  
  111. /* Client Name */
  112. 'Type' Client.Name
  113. call writeln('Out', Client.Name)
  114. call writeln('Out', "")
  115.  
  116. /* Date */
  117. call writeln('Out', date())
  118. call writeln('Out', "")
  119. call writeln('Out', "")
  120.  
  121. /* Work Description */
  122. call writeln('Out', "== WORK ===============================")
  123. call writeln('Out', "")
  124.  
  125. /* Work Description - Projects */
  126.  
  127. do lp = 1 to nProjects
  128.     if Projects.lp.Name ~= "" then do
  129.         call writeln('Out', "  "Projects.lp.Name)
  130.         call writeln('Out', "    -")
  131.     end
  132. end
  133.  
  134.  
  135. /* Expenses */
  136. TotalExpenses = 0
  137. if Expenses then do
  138.     call writeln('Out', "")
  139.     call writeln('Out', "== EXPENSES ===========================")
  140.     call writeln('Out', "")
  141.  
  142.     do lp = 1 to nProjects
  143.         if Expenses.lp.count = 0 then iterate
  144.  
  145.         call writeln('Out', "  "Projects.lp.Name)
  146.  
  147.         do lp2 = 1 to Expenses.lp.count
  148.             t = Expenses.lp.lp2.Info
  149.             if index(t, '","', index(t, '","')+3) = 0 then do
  150.                 parse var t '"'tInfo'","'tAmount'"'
  151.                 call writeln('Out', "    "tInfo"  "tAmount)
  152.                 end
  153.             else do
  154.                 parse var t '"'tInfo'","'tQuantity'","'tPer'","'tAmount'"'
  155.                 call writeln('Out', "    "tInfo" ("tQuantity" @ "tPer") "tAmount)
  156.             end
  157.  
  158.             TotalExpenses = TotalExpenses + tAmount
  159.         end
  160.     end
  161.  
  162.     call writeln('Out', "")
  163.     call writeln('Out', "    EXPENSES:  $"TotalExpenses)
  164. end
  165.  
  166.  
  167. Total = 0
  168. if Work then do
  169.     call writeln('Out', "")
  170.     /* Work Hours */
  171.     call writeln('Out', "== WORK HOURS =========================")
  172.     call writeln('Out', "")
  173.  
  174.     do lp = 1 to nProjects
  175.         if Projects.lp.count = 0 then iterate
  176.  
  177.         call writeln('Out', "  "Projects.lp.Name)
  178.  
  179.         HSubTotal = 0
  180.         do lp2 = 1 to Projects.lp.count
  181.             parse var Projects.lp.lp2.Info '"'tDate'","'tT1'","'tT2'","'tH'","'tRate'"'
  182.             call writeln('Out', "    "tDate"  "tT1"  -  "tT2"  "tH)
  183.             HSubTotal = HSubTotal + tH
  184.         end
  185.  
  186.         SubTotal = trunc(HSubTotal * tRate + .5e-2, 2)
  187.  
  188.         call writeln('Out', "      "HSubTotal" @ $"tRate" / hour:   "SubTotal)
  189.         Total = Total + SubTotal
  190.     end
  191.  
  192.     call writeln('Out', "")
  193.     call writeln('Out', "    WORK:  $"Total)
  194. end
  195.  
  196. call writeln('Out', "")
  197. call writeln('Out', "=======================================")
  198. call writeln('Out', "")
  199.  
  200. Total = Total + TotalExpenses
  201. call writeln('Out', "    TOTAL:  $"Total)
  202.  
  203. call writeln('Out', "")
  204. call writeln('Out', "=======================================")
  205. call writeln('Out', "")
  206. call writeln('Out', "Payment To:")
  207. call writeln('Out', "")
  208. call writeln('Out', "dhomas trenn")
  209. call writeln('Out', "797 Mitchell Street, Fredericton, NB   E3B 3S8")
  210. call writeln('Out', "(506) 459-7088")
  211. call close('Out')
  212.  
  213. /* Write Invoice Number */
  214. call open('Invoice', DataPath||Client.NameCode||".invoice", 'W')
  215. call writeln('Invoice', cInvoice)
  216. call close('Invoice')
  217.  
  218. /* Backup .time data file */
  219. ADDRESS COMMAND 'C:Rename' DataPath||Client.NameCode||".time" DataPath||Client.NameCode||".time."Client.Invoice
  220.  
  221. exit
  222.